#pragma once

#include "pch.h"
#include "Shader.h"

namespace Gut
{
    struct ShaderMng
    {
        std::string mDir = "resource/shader/";
        std::string versionHeader = " #version 300 es \n"
                                    "precision mediump float;\n";
        std::string mediumHeader = " precision mediump float; \n";

        const std::string GetVersionHeader() const
        {
            return this->versionHeader;
        };
        const std::string GetMediumHeader() const
        {
            return this->mediumHeader;
        }
        Shader CreatePath(const std::string &v, const std::string &p)
        {
            const std::string vf = mDir + v;
            const std::string pf = mDir + p;

            Shader shader;

            shader.CreateFromFilePath(vf, pf);
            const std::string vertCode = this->GetContexText(vf);
            const std::string fragCode = this->GetContexText(pf);

            // const std::string vvCode = GetVersionHeader() + vertCode;
            // const std::string ffCode = GetVersionHeader() + fragCode;
            const std::string vvCode = vertCode;
            const std::string ffCode = fragCode;

            shader.CreateFromCode(vvCode.c_str(), ffCode.c_str());

            return shader;
        }

        const std::string GetContexText(const std::string &path) const
        {
            std::ifstream ifs;
            ifs.open(path);
            if (!ifs.is_open())
            {
                LOGI("cannot open file %s \n", path.c_str());
                ifs.close();
                return "";
            }

            std::string text = std::string((std::istreambuf_iterator<char>(ifs)),
                                           (std::istreambuf_iterator<char>()));

            ifs.close();

            return text;
        }
    };
}